package com.eascs.admin.o2o.internal.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.admin.common.dao.BaseOaDao;
import com.eascs.admin.o2o.internal.entity.OaDeposit;
import com.eascs.admin.o2o.internal.entity.OaLoanapply;
import com.eascs.admin.o2o.internal.entity.OaStatus;
import com.eascs.overdue.entity.O2oStatus;

/**
 * 
 * 查询旧系统保证金和管理费情况
 *
 */
@Repository
public class O2oOaDao extends BaseOaDao {
	/**
	 * 查询贷款保证金金额
	 * @param billCode
	 * @return
	 */
	public OaLoanapply queryCode(String billCode){
		String sql="SELECT T.LOANAPPLYNO,L.IDCARD,L.LOANERNAME,T.BILLCODE ,T.BILLSTATUS,"
				+ "T.BILLCODEOTF,T.BILLSTATUSOTF,T.EXISTDEPOSIT,T.UNDEPOSIT FROM EADB.O2O_LOANAPPLY T "
				+ "JOIN EADB.O2O_LOANER L ON L.LOANAPPLYNO=T.LOANAPPLYNO WHERE T.ISLOCK='N' AND T.BILLCODE=?";
		return this.findEntity(sql, OaLoanapply.class, billCode);
	}
	/**
	 * 查询是否正在退费
	 * @param billCode
	 * @return
	 */
	public OaStatus queryBackDeposit(String billCode){
		String sql="SELECT L.BILLSTATUS FROM EADB.O2O_LOANAPPLY T JOIN EADB.O2O_BACKDEPOSITFEE L ON "
				+ "L.LOANAPPLYNO=T.LOANAPPLYNO WHERE T.ISLOCK='N' AND L.ISLOCK='N' AND T.BILLCODE=?";
		return this.findEntity(sql, OaStatus.class, billCode);
	}
	/**
	 * 查询借款是否有逾期
	 * @param billCode
	 * @return
	 */
	public List<O2oStatus> findOverdueBillCode(String billCode) {
		String sql="SELECT T.STATUS FROM EADB.O2O_OVERDUE_REPORT T WHERE T.ISNEW='Y' AND T.BILLCODE=?";
		return this.findEntitys(sql, O2oStatus.class, billCode);
	}
	/**
	 * 查询老系统可以退保证金单号
	 * @param idCard
	 * @return
	 */
	public List<OaDeposit> findBillCode(String idCard){
		String sql="SELECT T.BILLCODE,(T.EXISTDEPOSIT-T.UNDEPOSIT) AS TRANDEPOSIT,T.LOANAPPLYNO FROM "
				+ "EADB.O2O_LOANAPPLY T LEFT JOIN EADB.O2O_LOANER L ON L.LOANAPPLYNO=T.LOANAPPLYNO"
				+ " WHERE T.ISLOCK='N'  AND T.BILLSTATUSINFORM='CLO' AND (T.EXISTDEPOSIT-T.UNDEPOSIT)>0"
				+ " AND L.IDCARD=?";
		return this.findEntitys(sql, OaDeposit.class, idCard);
	}
}

